<?php
class Member_reg extends CI_Controller{
	public function __construct()
	{
		parent::__construct();
		//登录校验
		$this->common->check_login();
		//通过user_model的get_user_info_id方法获取个人信息
		$this->user_info = $this->user->get_user_info_id($_SESSION['user']['id']);
	}

	/**
	 * 注册我的会员
	 */
	public function index()
	{
		$this->load->helper('form');
		//var_dump($this->user_info);exit;
		$data['up_account'] = $this->user_info['user_account'];

		$data['left'] = $this->load->view('left', '', TRUE);

		$data['menu'] = $this->load->view('menu', '', TRUE);

		$this->load->view('member_reg', $data, FALSE);
	}

	/**
	 *会员注册
	 */
	public function info_post()
	{
		if ($_SESSION ['code'] != $_POST ['yzm']) {
			exit ( $this->common->alert_msg_goback ( '验证码错误' ) );
		}
		
		if(empty($_POST['mobile']))
		{

			exit($this->common->alert_msg_goback('参数错误'));
		}

		if($_POST['up_account'] != 'dedaozhe')
		{
			$up_user = $this->user->get_uesr_info($_POST['up_account']);

			if(empty($up_user) || $up_user['kick_status'] == 1)
			{
				exit ( $this->common->alert_msg_goback ( '推广账号不存在' ) );
			}

			$pid = $up_user['id'];

			$path = $up_user['path'];
		}
		else
		{
			$pid = 0;

			$path = '0/';
		}

		$mobile = $this->user->get_user_mobile($_POST['mobile']);

		if(!empty($mobile))
		{
			exit ( $this->common->alert_msg_goback ( '每个手机号只能注册一次' ) );
		}

		$info = $this->user->get_uesr_info($_POST['user_account']);//user_insert();


		if(!empty($info))
		{

			exit($this->common->alert_msg_goback('公益账号已经存在'));

		}
		else
		{
			// 插入
			$result = $this->user->user_insert ($pid);

			if($result)
			{
				$this->user->update_path($result,$path);

				$this->user->reg_digui_up_account($this->user_info['user_account']);

				exit($this->common->alert_msg_url('提交成功',site_url('member_reg')));

			}
			else
			{

				exit($this->common->alert_msg_goback('提交失败'));

			}

		}
	}
}